package io.zt.dangyuan;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * Created by Administrator on 2015/7/7.
 */
public class SimpleItemAdapter extends BaseAdapter {

    private LayoutInflater mInflater;
    private String[] titles;

    public SimpleItemAdapter(Context context, String[] titles) {
        this.mInflater = LayoutInflater.from(context);
        this.titles = titles;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return titles.length;
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return titles[arg0];
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.item_menu, null);
            holder.title = (TextView) convertView.findViewById(R.id.title);
            convertView.setTag(holder);

        } else {

            holder = (ViewHolder) convertView.getTag();
        }
        holder.title.setText(titles[position]);
        return convertView;
    }

    public final class ViewHolder {
        public TextView title;
    }

}
